<template>
  <div>
    <input type="text"  v-model="kw" placeholder="请输入关键词">
    <button @click="search_goods">搜索</button>
    <div>
      <ul>
        <li
          v-for='g in goods'
          :key="g.id"
        ><router-link :to="{'path':'/detail/', query:{'id':g.id}}">{{g.title}}</router-link></li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      kw: '',  // 搜索内容
      goods: [{
        id: 1,
        title: 'goods1',
        price: '99.99',
        show_num: 123,
        desc: '物美价廉, 走过路过, 不要错过,物美价廉, 走过路过, 不要错过,物美价廉, 走过路过, 不要错过,物美价廉, 走过路过, 不要错过,物美价廉, 走过路过, 不要错过,物美价廉, 走过路过, 不要错过'
      }]
    }
  },
  methods: {
    search_goods() {
      var params = {
        kw: this.kw
      }
      this.axios.get('http://127.0.0.1:8000/goods/search/', { params }).then(res => {
        var that = this
        console.log(res)
        // [{"id":1,"title":"13","price":"123.11","show_num":0,"desc":"haoyouduo"}]
        this.goods = res.data
        // this.total_goods = res.data.count
        // this.total_page = Math.ceil(this.total_goods / this.page_size)
        // debugger

      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style>
</style>